package cn.t12.qg.goodsconsumer.controler;

import cn.t12.qg.goodsconsumer.service.LocalGoodsService;
import cn.t12.qg.goodsconsumer.vo.GoodsVo;
import com.qg.dto.ReturnResult;
import com.qg.dto.ReturnResultUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
public class QgGoodsController {

    @Resource
    private LocalGoodsService localGoodsService;

    @PostMapping("/queryGoodsById")
    public ReturnResult queryGoodsById(String id) {
        GoodsVo qgGoods = localGoodsService.getById(id);
        return ReturnResultUtils.returnSuccess(qgGoods);
    }

    @PostMapping("/sendQgGoodsMessage")
    public ReturnResult sendQgGoodsMessage(String goodsId, String token) throws InterruptedException {
        // 调用业务层来发送一个抢购商品的消息
        localGoodsService.sendQgGoodsMessage(goodsId, token);
        return ReturnResultUtils.returnSuccess();
    }

    @PostMapping("/getGoodsStatus")
    public ReturnResult getGoodsStatus(String goodsId, String token)  {
        // 调用业务层来发送一个抢购商品的消息
        String status = localGoodsService.getGoodsStatus(goodsId, token);
        return ReturnResultUtils.returnSuccess(status);
    }
}
